<template>
	<view class="myTask">
		<view
			class="rl_item f f_column"
			v-for="(item,index) in myProject" :key="index"
		>
			<view class="f f_align_center" @click="chooseItem(item)">
				<view class="head_img project f_shrink0">
					<image :src="item.headImg" class="autoImg" mode=""></image>
				</view>
				<view class="f f_column f_align">
					<view class="f f_align_center mb12">
						<text class="bold re_name overfont">{{item.itemName}}</text>
						<view class="relase_tip_btn f_shrink0" v-if="item.itemTagType">{{$getDict(item_tag_type,item.itemTagType.split(',')[0])}}</view>
					</view>
					<view class="overfont-2">
						{{item.itemDetail}}
					</view>
					<view class="endTime mt10">{{item.createTime}}</view>
				</view>
			</view>
		</view>

		<!-- 加载 -->
		<loadMore :isLoading="isLoading" :isDone="isDoneTask" />
	</view>
</template>

<script>
	import loadMore from '@/components/loadMore/loadMore'
	import { mapState } from 'vuex'
	export default {
		components:{
			loadMore
		},
		data() {
			return {
				isLoading:false,
				isDoneTask:false,
				myProject:[],
				page:{
					pageIndex:1,
					limit:10,
					totalPage:0
				}
			};
		},
		computed:{
			...mapState({
				item_tag_type:state => state.dictArrs.item_tag_type
			})
		},
		onLoad() {
			this.$store.dispatch('getDictlists','item_tag_type');
		},
		onShow() {
			this.init();
		},
		methods:{
			//查询项目
			async init(){
				const _this = this;
				_this.isLoading = true;
				_this.isDoneTask = false;
				let res = (await _this.$http('/api/auth/item/listPersonItem','POST',{
					page:_this.page.pageIndex,
					limit:_this.page.limit
				})).data;
				uni.stopPullDownRefresh();
				_this.isLoading = false;
				if(res && res.code == '0'){
					let list = res.data.list;
					_this.page.totalPage = res.data.totalPage;
					if(_this.page.pageIndex <= 1){
						_this.myProject.splice(0);
					}
					if(_this.page.totalPage <= _this.page.pageIndex){
						_this.isDoneTask = true;
					}else{
						_this.isDoneTask = false;
					}
					_this.myProject = _this.myProject.concat(list);
				}else{
					_this.$showToast(res.msg);
				}
			},
			//确定任务
			chooseItem(item){
				this.$redTo(`../headLine/headLine?itemId=${item.itemId}&itemName=${item.itemName}`);
			}
		},
		onPullDownRefresh() {
			this.page.pageIndex = 1;
			this.init();
		},
		//滚动到底部
		onReachBottom() {
			const _this =this;
			if(_this.page.pageIndex < _this.page.totalPage){
				_this.page.pageIndex++;
				_this.init();
			}else{
				_this.isDoneTask = true;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myTask{
		box-sizing: border-box;
		width: 100%;
		min-height: 100vh;
		background-color: #F6F6F6;
		font-size: 24rpx;
		color: #999999;
		border-bottom: solid 2rpx #F6F6F6;
		.relase_tip_btn{
			font-size: 22rpx;
			color: $ych_color;
			border: solid 1rpx $ych_color;
			padding: 2rpx 8rpx;
			border-radius: 4rpx;
			margin-left: 8rpx;
		}
		.rl_item{
			padding: 24rpx;
			background-color: #fff;
			margin-top: 24rpx;
			border-top: solid 1rpx #F6F6F6;
			border-bottom: solid 1rpx #F6F6F6;
			.endTime{
				font-size: 20rpx;
			}
			.head_img{
				width: 90rpx;height: 90rpx;
				margin-right: 26rpx;
				&.radius{
					image{border-radius: 50%;}
				}
				&.project{
					width: 118rpx;height: 118rpx;
					margin-right: 20rpx;
				}
			}
			.re_name{
				font-size: 32rpx;
				color: #1A1A1A;
			}
			.re_margin{
				margin-left: 96rpx;
			}
			.re_price{
				font-size: 32rpx;
				color: #E6212A;
			}
		}
	}
</style>
